package com.tac.service.mes.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tac.common.result.Result;
import com.tac.dao.mes.JobAssemblyDao;
import com.tac.pojo.mes.JobAssembly;
import com.tac.service.mes.JobAssemblyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class JobAssemblyServiceImpl implements JobAssemblyService {

    @Autowired
    private JobAssemblyDao jobAssemblyDao;

    @Override
    public Result<PageInfo<JobAssembly>> getList(Integer pageNum, Integer pageSize,
                                                 String jobName, Date startTimeStart,
                                                 Date startTimeEnd, Date endTimeStart,
                                                 Date endTimeEnd) {
        PageHelper.startPage(pageNum, pageSize);
        List<JobAssembly> list = jobAssemblyDao.getList(jobName, startTimeStart,
                startTimeEnd, endTimeStart,
                endTimeEnd);
        PageInfo<JobAssembly> pageInfo = new PageInfo<>(list);
        return Result.success(pageInfo);
    }

    @Override
    public Result save(JobAssembly jobAssembly) {
        Integer result = jobAssemblyDao.save(jobAssembly);
        if (result > 0) {
            return Result.success(null);
        } else {
            return Result.error("保存失败");
        }
    }

    @Override
    public Result remove(List<Integer> ids) {
        Integer result = jobAssemblyDao.remove(ids);
        if (result > 0) {
            return Result.success(null);
        } else {
            return Result.error("删除失败");
        }
    }

    @Override
    public Result update(JobAssembly jobAssembly) {
        Integer result = jobAssemblyDao.update(jobAssembly);
        if (result > 0) {
            return Result.success(null);
        } else {
            return Result.error("更新失败");
        }
    }
}
